//
//  NXBeforeRegistController.m
//  NordsonTesco
//
//  Created by mac on 16/7/5.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "NXBeforeRegistController.h"
#import "PersonListCollectionViewCell.h"
#import "MerchantsRegisterViewController.h"
@interface NXBeforeRegistController ()<UICollectionViewDataSource, UICollectionViewDelegate>
{
    NSArray *ImgArray;

}
@property (nonatomic, strong) NSMutableArray *sourceArr;
@property (nonatomic, strong) UICollectionView *collectionView;

@end

@implementation NXBeforeRegistController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor whiteColor];
    ImgArray = @[@"User",@"Group",@"ds-b"];

    [self setupNavigationBar];
    [self setupCollectView];
}
//设置导航栏
- (void)setupNavigationBar
{
    // 颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 导航栏标题
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    title.text = @"用户注册";
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor whiteColor];
    title.font = [UIFont systemFontOfSize:17];
    title.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = title;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"return"] style:UIBarButtonItemStylePlain target:self action:@selector(didBackAction)];

}
-(void)didBackAction
{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - setupCollectView
- (void)setupCollectView
{
    UIView *greyV = [[UIView alloc]init];
    greyV.frame = CGRectMake(0, 64, kScrernWidth, 9);
    greyV.backgroundColor = greyHead_Color;
    [self.view addSubview:greyV];
    UIView *redLine = [[UIView alloc]init];
    redLine.frame = CGRectMake(0, 64+9, kScrernWidth, 1);
    redLine.backgroundColor = [UIColor colorWithRed:1.00 green:0.40 blue:0.42 alpha:1.00];
    [self.view addSubview:redLine];
    
    UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc] init];
    flowlayout.itemSize = CGSizeMake((kScrernWidth - 3) / 3, 120);
    flowlayout.minimumInteritemSpacing = 1;
    flowlayout.minimumLineSpacing = 1;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,  64+10, kScrernWidth, 120+1)collectionViewLayout:flowlayout];
    self.collectionView.backgroundColor = greyHead_Color;
    
//    [self.collectionView registerClass:[PersonListCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.collectionView registerNib:[UINib nibWithNibName:@"PersonListCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"PersonListCollectionViewCell"];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.view addSubview:self.collectionView];
}

#pragma mark - dataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//    PersonListCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    PersonListCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PersonListCollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    cell.ImgView.image = [UIImage imageNamed:ImgArray[indexPath.item]];
    cell.titLab.textColor = Textblack_Color;
    cell.titLab1.textColor = Textblack_Color;
    switch (indexPath.item) {
        case 0:
        {
            cell.titLab.text = @"消费者";
            cell.titLab1.text = @"免费注册";
        }
            break;
        case 1:
        {
            cell.titLab.text = @"联盟商家";
            cell.titLab1.text = @"免费注册";
        }
            break;
        case 2:
        {
            UILabel *lab = [[UILabel alloc]init];
            lab.frame = CGRectMake(0, CGRectGetMaxY(cell.ImgView.frame)+20, cell.frame.size.width, 20);
            lab.font =[UIFont systemFontOfSize:14];
            lab.textAlignment = NSTextAlignmentCenter;
            lab.textColor = Textblack_Color;

            lab.text =@"登录";
            [cell.contentView addSubview:lab];
        }
            break;
        default:
            break;
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.item ==1) {
        MerchantsRegisterViewController *merchant = [[MerchantsRegisterViewController alloc]init];
        [self.navigationController pushViewController:merchant animated:YES];
    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
